package com.zuowei.ycy.user.ui.mine.balance;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.and.yzy.frame.util.RetrofitUtils;
import com.zuowei.ycy.R;
import com.zuowei.ycy.user.config.UserManger;
import com.zuowei.ycy.user.http.Member;
import com.zuowei.ycy.ui.BaseToolbarAty;
import com.zuowei.ycy.user.util.AppJsonUtil;

import butterknife.Bind;
import butterknife.OnClick;
import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.Response;

/**
 * Created by Administrator on 2016/4/25.
 */
public class MineBalanceAty extends BaseToolbarAty {


    @Bind(R.id.tv_balance)
    TextView tvBalance;

    private float price;
    @Override
    public int getLayoutId() {
        return R.layout.mine_balacne_aty;
    }

    @Override
    public void initData() {
        mToolbar.setTitle("我的余额");

    }

    @Override
    public boolean setIsInitRequestData() {
        return true;
    }

    @Override
    protected void onResume() {
        super.onResume();
        doHttp(RetrofitUtils.createApi(Member.class).myBalance(UserManger.getM_id()), 0);
    }

    @Override
    public void requestData() {
        showLoadingContentDialog();
//        doHttp(RetrofitUtils.createApi(Member.class).myBalance(UserManger.getM_id()), 0);
    }

    @OnClick({R.id.tv_balance_zhuanchu, R.id.tv_balance_recharge, R.id.tv_balance_mingxi})
    @Override
    public void btnClick(View view) {
        super.btnClick(view);
        switch (view.getId()) {
            case R.id.tv_balance_zhuanchu:
                Bundle bundle = new Bundle();
                bundle.putFloat("price",price);
                startActivity(BalanceZhuanchuOneAty.class, bundle);
                break;
            case R.id.tv_balance_recharge:
                startActivity(RechargeOneAty.class, null);
                break;
            case R.id.tv_balance_mingxi:
                startActivity(ShouzhiMingxiAty.class, null);
                break;
        }
    }


    @Override
    public void onSuccess(String result, Call<ResponseBody> call, Response<ResponseBody> response, int what) {
        if (what == 0) {
            tvBalance.setText(AppJsonUtil.getString(result, "balance"));
            price = Float.parseFloat(AppJsonUtil.getString(result, "balance"));
        }
        super.onSuccess(result, call, response, what);
    }

}
